import LandService from "../../services/LandService";
import { injectReducer } from "../StoreUtil";
import InterfaceReducer from "./InterfaceReducer";
/**
 * 语言reducer
 *
 * @class LandReducer
 * @extends {InterfaceReducer}
 */
class LandReducer extends InterfaceReducer{
    
    constructor() {
        super({key: 'land', initState: {land: '', otherName: ''}})
        let land = LandService.getInitLang();
        this.initState = {land: land, otherName: land === "en" ? "en" : "zh-cn"}
    }

    //处理最终的修改数据
    getFinState = (value) => {
        let finValue = {};
        let _that = this;
        if(value.otherFn) {
            finValue = _that[value.otherFn](value)
        }else{
            for(let key in value) {
                if(this.initState[key]) {
                    finValue[key] = value[key];
                }
            }
        }
        finValue.otherName = finValue.land === "en" ? "en" : "zh-cn";
        return finValue
    }

}

export default injectReducer(LandReducer, false)